package com.lwc.service.impl;

import com.lwc.bean.User;
import com.lwc.bean.newUser;
import com.lwc.common.crud.BaseServiceImpl;
import com.lwc.common.exceotion.BusinessexCeption;
import com.lwc.mapper.UserMapper;
import com.lwc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl  implements UserService {

    @Autowired
    UserMapper userMapper;
    //注册
    @Override
    public int save(newUser newuser) {
//判断数据库这种是否有重复id
      int rs=  userMapper.selectByAccount(newuser.getUsername(),newuser.getPassword());

      if (rs>0){
          throw  new BusinessexCeption("注册失败 该账户密码已存在");
      }

        return userMapper.save(newuser);
    }

    @Override
    public User query(String username, String password) {
        //获取上次登录时间
        return userMapper.query(username,password);
    }

    @Override
    public int uodatepassword(int id, String password) {
        return  userMapper.uodatepassword(id,password);
    }


}
